package c

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.Fragment
import n.BG
import cc.bc.tc.R
import yyee.llee.mmee.base_api.um.UMKey
import yyee.llee.mmee.base_api.um.UTJ
import com.youth.banner.Banner
import com.youth.banner.indicator.CircleIndicator


/*
* @author lifeng
* @createTime 2024/4/19 1:39 PM
* @des 清理主页
*/
class DV : Fragment() {

    companion object {
        @JvmStatic
        fun newInstance() =
            DV().apply {
                arguments = Bundle().apply { }
            }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let { }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View? {
        val view = inflater.inflate(R.layout.fragment_c_l_e_a_n_m_a_i_n, container, false)
        initView(view)
        UTJ.onEvent(UMKey.main_show)
        return view
    }

    private fun initView(view: View) {
        initBannerView(view)
        initBaseFuncView(view)
        initOtherFuncView(view)

        val imageView: ImageView = view.findViewById(R.id.icon_setting)
        imageView.setOnClickListener {
            startActivity(Intent(requireContext(), BG::class.java))
        }
    }

    private fun initBannerView(view: View) {
        val models = listOf(
            DW(
                CLEAN_FUNC_TAG_laji,
                getString(R.string.home_banner_item_garbage),
                getString(R.string.home_banner_item_garbage_des),
                R.mipmap.bg_bdsc_before,
                "clean_main/clean_before"
            ),
            DW(
                CLEAN_FUNC_TAG_kadun,
                getString(R.string.home_banner_item_server),
                getString(R.string.home_banner_item_server_des),
                R.mipmap.bg_wxzq_before,
                "clean_main/speed_before"
            ),
            DW(
                CLEAN_FUNC_TAG_bingdu,
                getString(R.string.home_banner_item_virus),
                getString(R.string.home_banner_item_virus_des),
                R.mipmap.bg_bdsc_before,
                "clean_main/bdcs_before"
            ),
            DW(
                CLEAN_FUNC_TAG_weixin,
                getString(R.string.微信专清),
                getString(R.string.home_banner_item_weixin_des),
                R.mipmap.bg_wxzq_before,
                "clean_main/wxzq_before"
            ),
            DW(
                CLEAN_FUNC_TAG_jiangwen,
                getString(R.string.home_banner_item_cool),
                getString(R.string.home_banner_item_cool_des),
                R.mipmap.bg_bdsc_before,
                "clean_main/sjjw_before"
            )
        )

        val banner_new_home_top: Banner<DW, DU> =
            view.findViewById(R.id.banner_new_home_top)
        banner_new_home_top.setBannerRound(5.0f)
        val banner_adapter = DU(requireContext(), models)
        banner_adapter.addBannerItemCLick(DY { index, model ->
            Log.e(
                "DV",
                "DY $index ${model.funcTAG} ${model.funcName} ${model.funcDes}"
            )
            if (model.funcTAG == CLEAN_FUNC_TAG_laji) {
                DX.lajiqingli(requireActivity())
            } else if (model.funcTAG == CLEAN_FUNC_TAG_kadun) {
                DX.kamanyouhua(requireActivity())
            } else if (model.funcTAG == CLEAN_FUNC_TAG_bingdu) {
                DX.bingduchasha(requireActivity())
            } else if (model.funcTAG == CLEAN_FUNC_TAG_weixin) {
                DX.weixinqingli(requireActivity())
            } else if (model.funcTAG == CLEAN_FUNC_TAG_jiangwen) {
                DX.shoujijiangwen(requireActivity())
            }
        })
        banner_new_home_top.addBannerLifecycleObserver(this)//添加生命周期观察者
            .setAdapter(banner_adapter)
            .setIndicator(CircleIndicator(requireContext()));
    }

    private fun initBaseFuncView(view: View) {
        val ll_sjjs: LinearLayoutCompat = view.findViewById(R.id.ll_sjjs)
        val ll_hdyh: LinearLayoutCompat = view.findViewById(R.id.ll_hdyh)
        val ll_cdljql: LinearLayoutCompat = view.findViewById(R.id.ll_cdljql)
        val ll_sdql: LinearLayoutCompat = view.findViewById(R.id.ll_sdql)
        val ll_bdcs: LinearLayoutCompat = view.findViewById(R.id.ll_bdcs)
        val ll_wljs: LinearLayoutCompat = view.findViewById(R.id.ll_wljs)
        val ll_sjjw: LinearLayoutCompat = view.findViewById(R.id.ll_sjjw)
        val ll_wxzq: LinearLayoutCompat = view.findViewById(R.id.ll_wxzq)

        val ll_fangdajing: LinearLayout = view.findViewById(R.id.ll_fangdajing)
        val ll_saomiaoshibie: LinearLayout = view.findViewById(R.id.ll_saomiaoshibie)

        ll_sjjs.setOnClickListener {
            DX.kamanyouhua(requireActivity())
        }
        ll_hdyh.setOnClickListener {
            DX.haodianyouhua(requireActivity())
        }
        ll_bdcs.setOnClickListener {
            DX.bingduchasha(requireActivity())
        }
        ll_wljs.setOnClickListener {
            DX.wangluojiasu(requireActivity())
        }
        ll_sjjw.setOnClickListener {
            DX.shoujijiangwen(requireActivity())
        }
        ll_wxzq.setOnClickListener {
            DX.weixinqingli(requireActivity())
        }

        ll_fangdajing.setOnClickListener {
            DX.fangdajing(requireActivity())
        }

        ll_saomiaoshibie.setOnClickListener {
            DX.saomiaoshibie(requireActivity())
        }

        ll_cdljql.setOnClickListener {
            DX.dawenjianqingli(requireActivity())
        }
        ll_sdql.setOnClickListener {
            DX.shenduqingli(requireActivity())
        }
    }

    private fun initOtherFuncView(view: View) {
        val ll_ggql: ConstraintLayout = view.findViewById(R.id.ll_ggql)
        val ll_fzpjc: ConstraintLayout = view.findViewById(R.id.ll_fzpjc)
        val ll_eyrjjc: ConstraintLayout = view.findViewById(R.id.ll_eyrjjc)
        val ll_wifiaq: ConstraintLayout = view.findViewById(R.id.ll_wifiaq)

        val ll_dwjql: ConstraintLayout = view.findViewById(R.id.ll_dwjql)
        val ll_spzq: ConstraintLayout = view.findViewById(R.id.ll_spzq)
        val ll_gxbdk: ConstraintLayout = view.findViewById(R.id.ll_gxbdk)
        val ll_wxjc: ConstraintLayout = view.findViewById(R.id.ll_wxjc)
        val ll_dcjkbh: ConstraintLayout = view.findViewById(R.id.ll_dcjkbh)

        ll_ggql.setOnClickListener {
            DX.guanggaoqinglli(requireActivity())
        }
        ll_fzpjc.setOnClickListener {
            DX.fangzhapianjiance(requireActivity())
        }
        ll_eyrjjc.setOnClickListener {
            DX.eyiruanjianjiance(requireActivity())
        }
        ll_wifiaq.setOnClickListener {
            DX.wifianquan(requireActivity())
        }
        ll_dwjql.setOnClickListener {
            DX.dawenjianqingli(requireActivity())
        }
        ll_spzq.setOnClickListener {
            DX.suipianzhuanqing(requireActivity())
        }
        ll_gxbdk.setOnClickListener {
            DX.gengxinbingduku(requireActivity())
        }
        ll_wxjc.setOnClickListener {
            DX.weixinzhanghaojiance(requireActivity())
        }
        ll_dcjkbh.setOnClickListener {
            DX.dianchijiankangbaohu(requireActivity())
        }

        ////////////////////////////////////////////////////////

        val ll_spql: ConstraintLayout = view.findViewById(R.id.ll_spql)
        val ll_yyql: ConstraintLayout = view.findViewById(R.id.ll_yyql)
        val ll_tpql: ConstraintLayout = view.findViewById(R.id.ll_tpql)

        ll_spql.setOnClickListener {
            DX.shipinqingli(requireActivity())
        }
        ll_yyql.setOnClickListener {
            DX.yinyueqingli(requireActivity())
        }
        ll_tpql.setOnClickListener {
            DX.xiangceqingli(requireActivity())
        }


    }

}